
//there is a bug!!!overflow [solved]
//2000000009
//solved by test if(m = reverse_int(reverse_int(m)))
//call a wrapper to test over flow
//can't test it in impl, it won't terminate!!!

#include <iostream>
#include <cstdlib>
#include <stdexcept>
using namespace std;

//for-loop
unsigned int reverse_int_impl(unsigned int n)
{
  unsigned int m;
  for(m = 0;n!=0;n/=10)
    m = m * 10 + n % 10;
  return m;
}
unsigned int reverse_int(unsigned int n)
{
  if(n == reverse_int_impl(reverse_int_impl(n)) )
    return n;
  else {
    cout<<"..."<<endl;
    throw overflow_error("the integer is too large\n");
  }
}
int main(int argc, char *argv[])
{
  int m;
  if (argc == 2)
    m = atoi(argv[1]);
  else
    m = 1212;
  int r_m;
  try {
     r_m = reverse_int(m);
  }
  catch(exception& e){
    cout<<e.what()<<endl;
    return 1;
  }
  cout<<r_m<<endl;
  return 0;
}
